package br.com.gecandango.service.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import br.com.gecandango.beans.Contato;
import br.com.gecandango.service.ContatoService;

public class ContatoServiceImpl extends HibernateDaoSupport implements
	ContatoService {
	public Contato save(Contato bean) {
		Long id;
		if(bean.getId()==null){
			id =  (Long)getHibernateTemplate().save(bean);
			bean.setId(id);
		} else {
			getHibernateTemplate().saveOrUpdate(bean);
		}
		return bean;
	}
	public List<Contato> list() {
		return getHibernateTemplate().find("from Contato");
	}
	public Contato find(Long id) {
		List<Contato> e = (List<Contato>)getHibernateTemplate().find("from Contato where id=?", id);
		return e.get(0);
	}
	
	public void delete(Contato bean) {
		getHibernateTemplate().delete(bean);
	}
}
